package com.mnt.washio.activities;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;

import com.mnt.washio.R;
import com.mnt.washio.adapters.MenuListAdapter;
import com.mnt.washio.utils.Statics;

public class HelpActivity extends BaseActivity {

	private String[] mHelpIcons, mHelpTexts;
	private ListView mListView;
	private MenuListAdapter mAdapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_help);
		
		initView();
		initListeners();
	}

	@Override
	protected void initView() {
		super.initView();
		
		mHelpIcons = getResources().getStringArray(R.array.help_icons);
		mHelpTexts = getResources().getStringArray(R.array.help_texts);
		mListView = (ListView) findViewById(R.id.list_helps);
		mAdapter = new MenuListAdapter(this, mHelpIcons, mHelpTexts, R.layout.item_list_help);
		mListView.setAdapter(mAdapter);
	}

	private void initListeners() {
		mListView.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int pos,
					long arg3) {
				goToDetailPage(pos);
			}
		});
	}

	private void goToDetailPage(int pos) {
		String URL = "";
		Intent i = null;
		switch (pos) {
		case 0:
			i = new Intent(this, WalkThroughActivity.class);
			break;

		case 1:
			URL = Statics.FAQ_URL;
			break;

		case 2:
			i = new Intent(Intent.ACTION_CALL);
			i.setData(Uri.parse("tel:" + Statics.WASHIO_PHONE));
			break;

		case 3:
			i = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
					"mailto", "support@getwashio.com", null));
			i.putExtra(Intent.EXTRA_SUBJECT, "Send us Feedback");
			i.putExtra(Intent.EXTRA_TEXT, "Go on, tell us what you think.");

			break;

		case 4:
			URL = Statics.TERMS_URL;
			break;

		case 5:
			URL = Statics.PRIVACY_POLICY_URL;
			break;

		case 6:
			URL = Statics.EULA_URL;
			break;

		}
		
		if(URL.length()>0){
			i = new Intent(this, WebViewActivity.class);
			i.putExtra("URL", URL);
			i.putExtra("TITLE", mHelpTexts[pos]);
		}
		if(i != null){
			try {
				startActivity(i);
			} catch (Exception e) {}
			
		}
	}

}
